﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ApiCoreProject.Bll.Interface;
using ApiCoreProject.Model.Entities;
using System.Dynamic;
using Microsoft.AspNetCore.Authorization;

namespace ApiCoreProject.Api.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class UsersController : ControllerBase
    {
        private readonly IUsersServe usersServe;

        public UsersController(IUsersServe usersServe)
        {
            this.usersServe = usersServe;
        }

        [HttpGet]
        public dynamic Get(int size,int page,string name) {
            return usersServe.GetUsers(size, page, name);
        }

        [HttpPost]
        public dynamic Post([FromBody] User value)
        {
            value.LastTime = DateTime.Now;
            return usersServe.AddUsers(value);
        }

        [HttpPut("{id}")]
        public dynamic Put(int id, [FromBody] User value)
        {
            value.LastTime = DateTime.Now;
            return usersServe.UpdateUsers(id,value);
        }

        [HttpDelete("{id}")]
        public dynamic Delete(int id) {
            return usersServe.DeleteUsers(id);
        }
        
        [HttpDelete]
        [Route("batch")]
        public dynamic DeleteBatch(int[] ids)
        {
            return usersServe.DeleteBatch(ids);
        }


    }
}
